<?php
include 'templateSys/SQL.php';
include 'templateSys/Settings.php';
include 'templateSys/manager_util.php';
include 'templateSys/Admin.php';

if (isset($_POST['logout'])) {
    session_start();
    unset($_SESSION['SESS_MEMBER_ID']);
    header("location: ".Settings::$rootPath."".Settings::$manager."?action=logout");
    exit();
}

$link = getLink();
$query = sprintf(SQL::$select_user,
    mysql_real_escape_string($_POST["login"]),
    mysql_real_escape_string(hashByMatu($_POST["login"], $_POST["pass"]))
);

$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)) {
    session_start();
    session_regenerate_id();
    session_set_cookie_params(Settings::$sessionLifetime);
    $user= new Admin;
    $user->setAdminId($row['id']);
    $_SESSION['SESS_MEMBER_ID']=$user;
    session_write_close();
    header("location: ".Settings::$rootPath."".Settings::$manager."?action=eshop/addItem");
}
mysql_close($link);

?>
